package com.cloudream;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ScrollView;

import com.cloudream.toucheventdemo.R;
import com.cloudream.toucheventdemo.dispatchiner.MyListView;

import java.util.ArrayList;
import java.util.List;

public class DispatchInnerActivity extends AppCompatActivity {


    private MyListView myListView;

    private ScrollView scrollView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dispatch_inner);

        myListView = (MyListView)findViewById(R.id.mListView);

        scrollView = findViewById(R.id.scrollView);


        int screenHeight = getResources().getDisplayMetrics().heightPixels;
        Log.d("MyScrollView", "screenHeight:" + screenHeight);
        int headViewHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                100, getResources().getDisplayMetrics());

       LinearLayout.LayoutParams lp  = (LinearLayout.LayoutParams) myListView.getLayoutParams();
        lp.height =screenHeight -headViewHeight;


        myListView.setmParentState(new MyListView.IParentState() {
            @Override
            public boolean canScrollDown() {
                return scrollView.canScrollVertically(-1);
            }

            @Override
            public boolean canScrollUp() {
                return scrollView.canScrollVertically(1);
            }
        });

        List<String> data = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            data.add("---- "+i+" ----");
        }


        myListView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,data));

    }






}
